import React, {Component} from 'react';
import {Redirect, Switch, Route} from "react-router-dom"
import memoryUtils from "../../utils/memoryUtils";
import {Layout} from "antd"
import Header from "../../components/header";
import LeftNav from "../../components/left-nav";
import Home from "../home/home";
import Category from "../category/category";
import Order from "../order/order";
import Product from "../product/product";
import Role from "../role/role";
import User from "../user/user";
import Bar from "../chart/bar";
import Line from "../chart/line";
import Pie from "../chart/pie";

const {Footer, Sider, Content} = Layout;

class Admin extends Component {

    render() {
        const user = memoryUtils.user
        // console.log('uu', user)
        // 如果内存没有存储user =>当前没有登录
        if (!user || !user._id) {
            // 自动跳转到登录界面
            return <Redirect to="/login"/>
        }
        return (
            <Layout style={{height: '100%'}}>
                <Sider>
                    <LeftNav/>
                </Sider>
                <Layout>
                    <Header>Header</Header>
                    <Content style={{margin: 20, backgroundColor: '#fff'}}>
                        <Switch>
                            <Route path='/home' component={Home}/>
                            <Route path='/category' component={Category}/>
                            <Route path='/product' component={Product}/>
                            <Route path='/role' component={Role}/>
                            <Route path='/user' component={User}/>
                            <Route path='/charts/bar' component={Bar}/>
                            <Route path='/charts/line' component={Line}/>
                            <Route path='/charts/pie' component={Pie}/>
                            <Redirect to='/home'/>
                        </Switch>
                    </Content>
                    <Footer style={{color: 'gray', textAlign: 'center'}}>推荐使用谷歌浏览器， 可以获得更佳页面操作体验</Footer>
                </Layout>
            </Layout>
        );
    }
}

export default Admin;
